const mongoose = require('./db');
const { orderModel } = require('./db');

// 用户提供的真实图片映射
const imgMap = {
  '布洛芬缓释胶囊': 'https://img.yzcdn.cn/vant/cat.jpeg',
  '美林 布洛芬小儿混悬液': 'https://img.yzcdn.cn/vant/leaf.jpg',
  '阿莫西林胶囊': 'https://img.yzcdn.cn/vant/apple-1.jpg'
};

(async () => {
  await mongoose.connection;
  const orders = await orderModel.find();
  console.log(orders);
  
  let changed = 0;
  for (const order of orders) {
    const name = order.medicine?.name;
    if (name && imgMap[name]) {
      order.medicine.img = imgMap[name];
      await order.save();
      changed++;
      console.log(`已写入真实图片: ${name}`);
    }
  }
  console.log(`批量写入完成，共${changed}条图片`);
  mongoose.disconnect && mongoose.disconnect();
})(); 